package pack0831.demo;

import java.util.ArrayList;
import java.util.List;

public class Bridge {
    private List<Person> list = new ArrayList<>();
    private final  int max = 3;
    public synchronized void up(Person person){
        if (list.size()==max){
            System.out.println("桥满了，不能再上了");
            try {
                wait();
            }catch (Exception e){}
        }
        list.add(person);
        notify();
    }
    public synchronized Person down(){
        if (list.size()==0){
            System.out.println("桥空了，500斤以下随便走");
            try {
                wait();
            }catch (Exception e){}
        }
        Person person = list.get(0);
        list.remove(0);
        notify();
        return person;
    }
}
